<?php
/**
* エラーチェッククラス
**/
require_once( '../system/Class_M_DAO.php' );
class Class_M_NEWYEAR_WEEK extends Class_M_DAO {
	//protected properties begin
	/**
	 *
	 * テーブル名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_table = "M_NEWYEAR_WEEK";
	
	/**
	 *
	 * 主キー名
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	protected $_pkey = "id";
	
	/**
	 *
	 * ソート順
	 *
	 * @access    protected
	 * @var       string
	 *
	 */
	 protected $_order = "id";
	 
	 protected $_cols     = array(
	 	"year4"      => array(AOKI_VARTYPE_STR),
		"matrix_cd1" => array(AOKI_VARTYPE_STR),
		"week1"      => array(AOKI_VARTYPE_STR),
		"matrix_cd2" => array(AOKI_VARTYPE_STR),
		"week2"      => array(AOKI_VARTYPE_STR),
		"matrix_cd3" => array(AOKI_VARTYPE_STR),
		"week3"      => array(AOKI_VARTYPE_STR),
		"matrix_cd4" => array(AOKI_VARTYPE_STR),
		"week4"      => array(AOKI_VARTYPE_STR),
	 );
	
	 protected $_checks  = array(
		"year4"      => array( "EXIST" ),
	 );
	 
	 //maxlength 
	 protected $_maxlens  = array(
		"year4"      =>  4,
	 );
	 
	public function getByYear($value) {
		$sql = sprintf("SELECT * FROM {$this->_table} WHERE year4 = '%s'" , $this->esc( $value ) );
		$this->_db->query( $sql );
		if( $this->_db->num_rows() ){
			$retrow =  $this->_db->fetch();
			if (isset($retrow["u_user"]) && ($retrow["u_user"])) {
				$sql = sprintf("SELECT user_name FROM  M_LOGIN  WHERE id = '%s'" , $retrow["u_user"]);
				$this->_db->query( $sql );
				if( $this->_db->num_rows() ){
					$userrow = $this->_db->fetch();
					$retrow["m_user_name"] = $userrow['user_name'];
				}else {
					$retrow["m_user_name"] = $retrow["u_user"];
				}
			}
			return $retrow;
		}else{
			return  FALSE;
		}
	}
		 
	public function  update_newyear($values){
		$week1 = $values["week1"] ;
		$week2 = $values["week2"] ;
		$week3 = $values["week3"] ;
		$week4 = $values["week4"] ;
		
		$sql = "update M_NEWYEAR set  memo_day1 ='$week1', memo_day2 ='$week2', memo_day3 ='$week3', memo_day4 ='$week4'  " ;
		try {
			if (! $this->_db->query( $sql )) {
			return   FALSE;
			}
			return TRUE;
		} catch (Exception $e) {
			echo "例外キャッチ：", $e->getMessage(), "\n";
			return  FALSE;
			break;
		}
		
	 }
	
}

?>